package io.plus.engine.pulse;

import lombok.Data;
import lombok.NonNull;

import java.util.Objects;

@Data
public class Node implements Comparable<Node> {
    private String ip;
    private int port;

    public Node(@NonNull String ip, @NonNull int port) {
        super();
        this.setIp(ip);
        this.setPort(port);
    }

    @Override
    public int compareTo(Node node) {
        if (node == null) {
            return -1;
        }
        if (Objects.equals(ip, node.getIp()) && Objects.equals(port, node.getPort())) {
            return 0;
        } else {
            return this.toString().compareTo(node.toString());
        }
    }

    @Override
    public boolean equals(Object object) {
        if (object == null) {
            return false;
        }
        Node node = (Node) object;
        return ip.equals(node.getIp()) && port == node.getPort();
    }

}
